//
//  RiseUpViewController.m
//  LiquorChain
//
//  Created by apple on 2018/12/25.
//  Copyright © 2018年 王冬. All rights reserved.
//

#import "RiseUpViewController.h"
#import "RiseUpViewCell.h"
#import "InviteViewController.h"
#import "MyFriendController.h"
#import "FollowWxController.h"
#import "AddgroupController.h"
#import "GuideViewController.h"
#import "RewardController.h"
#import "AreaViewController.h"
@interface RiseUpViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIView *backView;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *titleArray1;
@property (nonatomic,strong) NSArray *titleArray2;
@end

@implementation RiseUpViewController
-(NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray =[NSArray array];
        
    }
    return _titleArray;
}
static NSString *CellIdentifier = @"riseCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor groupTableViewBackgroundColor];
    self.navigationItem.title = @"酿力任务";
    
    self.titleArray =@[@"酒链大师",@"酒链商城",@"我的粉丝",@"大师奖励",@"区域合作"];
    self.titleArray1 =@[@"关注公众号",@"客服扫码群"];
    self.titleArray2 =@[@"每日登陆",@"添加地址",@"操作指南",@"大商学院"];
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(15, kNavBarHeight, SCREEN_WIDTH -30, SCREEN_HEIGHT - kNavBarHeight -kIPhoneXBottomHeight) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"RiseUpViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
    self.tableView.clipsToBounds =NO;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
  
   
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   
    if (section == 0) {
        
        UIImageView *view =[[UIImageView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH-30, 194)];
        view.backgroundColor =[UIColor redColor];
        view.clipsToBounds = NO;
        UIImageView *ima =[[UIImageView alloc]initWithFrame:CGRectMake(-15, 0, SCREEN_WIDTH, 194)];
        ima.backgroundColor =[UIColor blueColor];
         [view addSubview:ima];
        
        UILabel *topLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH-30, 44)];
        topLabel.text = @"  推荐任务";
        topLabel.backgroundColor =[UIColor whiteColor];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:topLabel.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
        CAShapeLayer *maskLayer =[[CAShapeLayer alloc]init];
        maskLayer.frame = topLabel.bounds;
        maskLayer.path = maskPath.CGPath;
        topLabel.layer.mask = maskLayer;
        [view addSubview:topLabel];
        return view;
    }else{
        UILabel *topLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-30, 50)];
        topLabel.backgroundColor =[UIColor whiteColor];
        UIBezierPath *maskPath  =[UIBezierPath bezierPathWithRoundedRect:topLabel.bounds cornerRadius:UIRectCornerTopLeft|UIRectCornerTopRight];
        CAShapeLayer *maskLayer =[[CAShapeLayer alloc]init];
        maskLayer.frame = topLabel.bounds;
        maskLayer.path = maskPath.CGPath;
        topLabel.layer.mask = maskLayer;
        if (section==1) {
            topLabel.text = @"  活跃任务";
        }
        if (section ==2) {
             topLabel.text = @"  基础任务";
        }
        return topLabel;
    }
   
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-30, 23)];
    UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-30, 10)];
    [footView addSubview:backView];
    backView.backgroundColor =[UIColor whiteColor];
    
    UIBezierPath *maskPath =[UIBezierPath bezierPathWithRoundedRect:backView.bounds byRoundingCorners:UIRectCornerBottomRight|UIRectCornerBottomLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *maskLayer =[[CAShapeLayer alloc]init];
    maskLayer.frame = backView.bounds;
    maskLayer.path = maskPath.CGPath;
    backView.layer.mask = maskLayer;
    
    footView.backgroundColor =[UIColor groupTableViewBackgroundColor];
    return footView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 23;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section ==0) {
        return 194;
    }else{
        return 50;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section ==0) {
        return 5;
    }
    if (section ==1) {
        return 2;
    }
    if (section ==2) {
        return 4;
    }
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RiseUpViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.cellIndexPath = ^{
        NSLog(@"%ld",indexPath.row);
        [MBProgressHUD showSuccess:[NSString stringWithFormat:@"点击了第%ld%@",indexPath.row,@"行"] toView:self.view];
        
    };
    if (indexPath.section ==0) {
        cell.titleLabel.text = self.titleArray[indexPath.row];
    }if (indexPath.section ==1) {
         cell.titleLabel.text = self.titleArray1[indexPath.row];
    }if (indexPath.section ==2) {
        cell.titleLabel.text = self.titleArray2[indexPath.row];
    }
   
   // cell.textLabel.text = @"asa";
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section ==0) {
        if (indexPath.row ==0) {
            InviteViewController *inVC =[[InviteViewController alloc]init];
            [self.navigationController pushViewController:inVC animated:YES];
        }
        if (indexPath.row ==2) {
            MyFriendController *myfVC =[[MyFriendController alloc]init];
            [self.navigationController pushViewController:myfVC animated:YES];
        }
        if (indexPath.row ==3) {
            RewardController *rewVC =[[RewardController alloc]init];
            [self.navigationController pushViewController:rewVC animated:YES];
        }
        if (indexPath.row ==4) {
            AreaViewController *areaVC =[[AreaViewController alloc]init];
            self.navigationController.navigationBar.hidden = YES;
            [self.navigationController pushViewController:areaVC  animated:YES];
        }
    }
    if (indexPath.section ==1) {
        if (indexPath.row ==0) {
            FollowWxController *folleVC =[[FollowWxController alloc]init];
            [self.navigationController pushViewController:folleVC animated:YES];
        }
        if (indexPath.row ==1) {
            AddgroupController *addVC =[[AddgroupController alloc]init];
            [self.navigationController pushViewController:addVC animated:YES];
        }
    }
    if (indexPath.section ==2) {
        if (indexPath.row == 2 || indexPath.row ==3) {
            GuideViewController *guiVC =[[GuideViewController alloc]init];
            [self.navigationController pushViewController:guiVC animated:YES];
        }
    }
}
@end
